﻿using System;
using System.Collections;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Converters;

namespace Charts.Converters
{
	public class PointsToMarkersConverter : ConverterBase<PointsToMarkersConverter>
	{
		public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			try {

				PointCollection points = (PointCollection)value;
				Geometry pg = (Geometry)parameter;
				return new GeometryCollection(points
				                              .AsEnumerable()
				                              .Select(e => {
				                                      	var g = pg.Clone();
				                                      	g.Transform = new TranslateTransform(e.X, e.Y);
				                                      	return g;
				                                      }));

			} catch (Exception) { return DependencyProperty.UnsetValue; }
		}
	}
}
